<template>
  <el-config-provider :locale="elementLanguage"
    v-if="languageJson && languageJson.menus != null && languageJson.menus != undefined">
    <RouterView :style="{
      '--pcmain-color': pcmainColor,
      '--pcvice-color': pcviceColor,
      '--primary': pcmainColor,
      '--el-color-primary': pcmainColor,
      '--el-checkbox-checked-bg-color': pcmainColor,
      '--el-checkbox-checked-input-border-color': pcmainColor,
      '--PingFangSC': PingFangSC,
      '--AlibabaPuHuiTi285': AlibabaPuHuiTi285,
      '--AlibabaPuHuiTi265': AlibabaPuHuiTi265,
      '--AlibabaPuHuiTi255': AlibabaPuHuiTi255,
      '--DINAlternate': DINAlternate,
    }" />
    <app-app-update />
    <SettingIndex v-if="settingStores.showdialog" v-model="settingStores.showdialog" />
  </el-config-provider>
</template>

<script setup>
import { getVersion } from '@/utils/getVersion'
import { getAppPackage } from '@/utils/getAppPackage'
import { onMounted, provide } from 'vue'
import { settingStore } from '@/stores/setting.js'
import en from 'element-plus/es/locale/lang/en'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import SettingIndex from '@/views/setting/index.vue'

import PingFangSC from '@/assets/font/PingFang-SC-Regular.ttf';
import AlibabaPuHuiTi_2_85_ from '@/assets/font/._AlibabaPuHuiTi-2-85-Bold.ttf';
import AlibabaPuHuiTi_2_65_ from '@/assets/font/._AlibabaPuHuiTi-2-65-Medium.ttf';
import AlibabaPuHuiTi_2_55_ from '@/assets/font/._AlibabaPuHuiTi-2-55-Regular.ttf';
import DINAlternate from '@/assets/font/DINEngAlt.ttf';

const userStore = useUserStore()
const activeverison = ref('')
const packageJs = ref({})
const pcmainColor = ref('#ff7900')
const pcviceColor = ref('#75b5ea')

// const PingFangSC = ref('PingFangSC')
// const AlibabaPuHuiTi285 = ref('AlibabaPuHuiTi_2_85_')
// const AlibabaPuHuiTi265 = ref('AlibabaPuHuiTi_2_65_')
// const AlibabaPuHuiTi255 = ref('AlibabaPuHuiTi_2_55_')
// const DINAlternate = ref('DINAlternate')

const settingStores = settingStore()
const languageJson = ref({})
const languageType = ref('')
const elementLanguage = ref(zhCn)
provide('languageJson', languageJson)
provide('languageType', languageType)

// const languageJson = inject('languageJson')
// const languageType = inject('languageType')

const getlanguage = async () => {
  let language = localStorage.getItem(`sp_language`)
  let navlanguage = navigator.language || navigator.userLanguage
  if (language) {
    userStore.language.type = language
    await userStore.getlanguage()
    languageJson.value = userStore.language.data
    languageType.value = localStorage.getItem(`sp_language`)
  } else {
    userStore.language.type = navlanguage == 'zh-CN' ? 'zh' : 'en'
    await userStore.getlanguage()
    languageJson.value = userStore.language.data
    languageType.value = localStorage.getItem(`sp_language`)
  }


  if (languageType.value == 'en') {
    elementLanguage.value = en
    const styleTag = document.createElement('style');
    styleTag.innerHTML = `
  @font-face {
  font-family: 'PingFangSC';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_85_';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_65_';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_55_';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DINAlternate';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

*,
body {
  font-family: PingFangSC;
  user-select: none;
}
`;


    
    document.head.appendChild(styleTag);
  } else if (languageType.value == 'zh') {
    elementLanguage.value = zhCn
    const styleTag = document.createElement('style');
    styleTag.innerHTML = `
  @font-face {
  font-family: 'PingFangSC';
  src: url(${PingFangSC}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_85_';
  src: url(${AlibabaPuHuiTi_2_85_}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_65_';
  src: url(${AlibabaPuHuiTi_2_65_}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_55_';
  src: url(${AlibabaPuHuiTi_2_55_}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DINAlternate';
  src: url(${DINAlternate}) format('truetype');
  font-weight: normal;
  font-style: normal;
}

*,
body {
  font-family: PingFangSC;
  user-select: none;
}
`;
    document.head.appendChild(styleTag);
  }


}


onMounted(async () => {
  console.log(import.meta.env);
  activeverison.value = await getVersion()

  packageJs.value = await getAppPackage() // 获取electron中的package.json内容
  userStore.savepackageJs(packageJs.value)

  document.title = `${packageJs.value.productName} V${activeverison.value}` //  设置标题为产品名称 + 版本号
  pcmainColor.value = packageJs.value.productColors.pcmainColor //  设置公共主颜色
  pcviceColor.value = packageJs.value.productColors.pcviceColor //  设置公共次颜色
  document.documentElement.style.setProperty('--pcmain-color', pcmainColor.value) //  全局设置公共主颜色变量
  document.documentElement.style.setProperty('--pcvice-color', pcviceColor.value) //  全局设置公共副颜色变量

  // 设置软件标题
  if (window.SDK && typeof window.SDK.receive === 'function') {
    window.SDK.receive('set-window-title', data => {
      const intervalId = setInterval(() => {
        if (document.title == data.title) {
          clearInterval(intervalId)
        } else {
          document.title = data.title
        }
      }, 1000)
    })
  }

  if (window.SDK && typeof window.SDK.receive === 'function') {
    window.SDK.receive('add-window-model', data => {
      console.log(data)
    })
  }
  getlanguage()

  // languageJson.value = languageStore.textjson
})
</script>

<style id="fontStyle">
/* @font-face {
  font-family: 'PingFangSC';
  src: url('@/assets/font/PingFang-SC-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_85_';
  src: url('@/assets/font/._AlibabaPuHuiTi-2-85-Bold.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_65_';
  src: url('@/assets/font/._AlibabaPuHuiTi-2-65-Medium.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_55_';
  src: url('@/assets/font/._AlibabaPuHuiTi-2-55-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DINAlternate';
  src: url('@/assets/font/DINEngAlt.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

*,
body {
  font-family: PingFangSC;
  user-select: none;
} */
</style>

<style>
*,
body {
  font-family: PingFangSC;
  user-select: none;
}
.el-select-dropdown__item.is-selected {
  color: var(--pcmain-color) !important;
}

.el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

.el-radio__input.is-checked .el-radio__inner {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

.el-select .el-select__wrapper,
.el-input-number .el-input__wrapper,
.el-input .el-input__wrapper {
  border-radius: 0 !important;
}

.el-switch.is-checked .el-switch__core {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

.el-select__wrapper.is-focused {
  box-shadow: 0 0 0 1px var(--pcmain-color) inset;
}

.el-button {
  border-radius: 0 !important;
}


.el-select-dropdown__item.is-selected {
  color: var(--pcmain-color) !important;
}

.el-dropdown-menu__item:not(.is-disabled):hover,
.el-dropdown-menu__item:not(.is-disabled):focus {
  color: var(--pcmain-color) !important;
}

.hovepcvicecolor:hover {
  background-color: var(--pcmain-color) !important;
  border-color: var(--pcmain-color) !important;
}

.el-input .el-input__wrapper.is-focus {
  border-color: var(--pcmain-color) !important;
  box-shadow: 0 0 0 1px var(--pcmain-color) inset;
}

.AlibabaPuHuiTi_2_55_ {
  font-family: AlibabaPuHuiTi_2_55_;
}

.AlibabaPuHuiTi_2_65_ {
  font-family: AlibabaPuHuiTi_2_65_ ;
}

.AlibabaPuHuiTi_2_85_ {
  font-family: AlibabaPuHuiTi_2_85_;
}

.DINAlternate {
  font-family: DINAlternate;
}

.PingFangSC {
  font-family: PingFangSC;
}

.el-scrollbar__bar.is-vertical {
  width: 4px;
  border: 0;
}

.el-scrollbar__bar.is-vertical .el-scrollbar__thumb {
  background-color: rgb(220, 222, 240);
  opacity: 1;
  border-radius: 0px;
}

.select_popper_border0 {
  border-radius: 0;
}
</style>
